/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mscs.server.globalManager.view;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import mscs.data.pojo.Goods;

/**
 *
 * @author Administrator
 */
public class TableModelFactory {
    public final static Vector<String> GOODS_COLUMN_NAMES = new Vector(Arrays.asList("标识","描述","售价"));
    
    public static DefaultTableModel getNullGoodsTableModel(){
        return new DefaultTableModel(null, GOODS_COLUMN_NAMES);
    }
 
    public static Vector<Vector<String>> toDataVector(List<Goods> list){
        Vector<Vector<String>> newVector = new Vector<Vector<String>>();
        for(Goods goods: list){
            newVector.add(toStringArray(goods));
        }
        return newVector;
    }
    
    private static Vector<String> toStringArray(Goods goods){
        Vector<String> list = new Vector<String> ();
        list.add(goods.getId());
        list.add(goods.getDesc());
        list.add(String.valueOf(goods.getSalPrice()));
        return list;
    }
}
